package com.github.skystardust.lotteryex.lottery.bundle.profile;

import org.bukkit.configuration.serialization.ConfigurationSerializable;

import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;

public class LotteryProfile implements ConfigurationSerializable {
    private int chance;
    private Map<String, Double> specChancePermissionMap;

    public LotteryProfile(int chance, Map<String, Double> specChancePermissionMap) {
        this.chance = chance;
        this.specChancePermissionMap = specChancePermissionMap;
    }

    public LotteryProfile(Map<String, Object> stringObjectMap) {
        this.chance = (int) stringObjectMap.get("chance");
        this.specChancePermissionMap = (Map<String, Double>) stringObjectMap.get("specChancePermissionMap");
    }

    private LotteryProfile(Builder builder) {
        chance = builder.chance;
        specChancePermissionMap = builder.specChancePermissionMap;
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    @Override
    public Map<String, Object> serialize() {
        HashMap<String, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("chance", chance);
        objectObjectHashMap.put("specChancePermissionMap", specChancePermissionMap);
        return objectObjectHashMap;
    }

    public static final class Builder {
        private int chance;
        private Map<String, Double> specChancePermissionMap;

        private Builder() {
        }

        @Nonnull
        public Builder withChance(int val) {
            chance = val;
            return this;
        }

        @Nonnull
        public Builder withSpecChancePermissionMap(@Nonnull Map<String, Double> val) {
            specChancePermissionMap = val;
            return this;
        }

        @Nonnull
        public LotteryProfile build() {
            return new LotteryProfile(this);
        }
    }
}
